package com.idanchuang.count.core.domain;

import com.idanchuang.count.core.entity.SimpleCountIncrEvent;
import lombok.Data;

/**
 * @author Richard_yyf
 * @version 1.0 2021/10/12
 */
@Data
public class AnalyzeCounter {

    private Long ts;
    private Long increment;

    /**
     * 子表名只能由字母、数字和下划线组成，所以不符合的bizNo会插入失败
     */
    private String bizNo;

    /**
     * 子表名只能由字母、数字和下划线组成 所以 AnalyzeCounter 中的 bizCode 需要做替换
     * 用来拼接表名
     */
    private String bizCode;

    public static AnalyzeCounter buildFrom(SimpleCountIncrEvent incrEvent) {
        AnalyzeCounter counter = new AnalyzeCounter();
        counter.setTs(Long.valueOf(incrEvent.getTs()));
        counter.setIncrement(Long.valueOf(incrEvent.getIncrement()));
        counter.setBizNo(incrEvent.getBizNo());
        counter.setBizCode(incrEvent.getBizCode().replaceAll("-", "_"));
        return counter;
    }
}
